﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.ComplexEventProcessing;
using Microsoft.ComplexEventProcessing.Adapters;
using Microsoft.Samples.SmartGrid.AMI.MeterEventType;

namespace Microsoft.Samples.SmartGrid.AMI.WcfInputAdapter
{
    public class WcfInputAdapterFactory:ITypedInputAdapterFactory<WcfInputAdapterConfig>, ITypedDeclareAdvanceTimeProperties<WcfInputAdapterConfig>
    {

        internal static readonly string ADAPTER_NAME = "AMI.WcfInput";

        public InputAdapterBase Create<TPayload>(WcfInputAdapterConfig configInfo, EventShape eventShape)
        {
            InputAdapterBase ret = default(InputAdapterBase);

            switch (eventShape)
            {
                case EventShape.Point:
                    ret = new WcfInputPointAdapter(configInfo);
                    break;
                default:
                    throw new ApplicationException("Only Point Adapters are Available!");
            }
            return ret;
        }

        public void Dispose()
        {
           
        }

        public AdapterAdvanceTimeSettings DeclareAdvanceTimeProperties<TPayload>(WcfInputAdapterConfig configInfo, EventShape eventShape)
        {
            //hardcoded number
            var timeGenSettings = new AdvanceTimeGenerationSettings(configInfo.CtiFrequency, TimeSpan.FromTicks(-1), true);
            return new AdapterAdvanceTimeSettings(timeGenSettings, AdvanceTimePolicy.Adjust);
        }
    }
}
